import { http } from "@/utils/http";
import type { FormRules } from "element-plus";

/** 获取电子界桩列表结果 */
export type Result<T> = {
  code: number;
  msg: string;
  data: {
    list: T;
    total: number;
  };
};

/** MyDialog */
export interface MyDialog<T> {
  title: string;
  visible: boolean;
  form: T;
  rules?: FormRules;
}

/** 振动枚举 */
export enum VIBRATE {
  NO_VIBRATION = 0,
  THERE_IS_VIBRATION = 1
}

/** 报文枚举 */
export enum NETWORK_TYPE {
  WARNING = 1, // 报警报文
  TIMING = 2 // 定时报文
}

/** 报文协议枚举 */
export enum PROTOCOL_TYPE {
  BASICS = 0, // 基础报文
  EBM_JW_S350 = 1 // 电子界桩JW-S350报文
}

/** 电子界桩修改接口 */
export interface EbmUpdateParams {
  id: number;
  version: string;
  tcp1Ip: string;
  tcp1Port: number;

  tcp2Enable: boolean;
  tcp2Protocol: PROTOCOL_TYPE;
  tcp2Ip: string;
  tcp2Port: number;

  tcp3Enable: boolean;
  tcp3Protocol: PROTOCOL_TYPE;
  tcp3Ip: string;
  tcp3Port: number;

  sampleInv: number;
  uploadInv: number;
  shockThreshold: number;
  remark: string;
  groupId: number;
}

/** 电子界桩实体接口 */
export interface Ebm extends EbmUpdateParams {
  deviceSn: string;
  tcp1Protocol: PROTOCOL_TYPE;
  tcp1Enable: boolean;
  uploadDataTime: number; // 设备最新上传数据时间秒级时间戳
  lon: number;
  lat: number;
  temp: number; // 温度
  humidity: number; // 湿度
  zd: VIBRATE; //振动
  angle: number; // z轴角度
  volt: number; // 设备电压
  type: NETWORK_TYPE; // 设备类型
  createdAt: string; // 创建时间
}

/** 电子界桩查询参数 */
export interface EbmParams {
  pageSize: number;
  pageNum: number;
  remark: string;
  sn: string;
  groupId: number;
}

export type EbmList = Array<Ebm>;
/**
 * 查询电子界桩列表
 */
export const getEbmListApi = (params: EbmParams) => {
  return http.request<Result<EbmList>>("get", "/forward", {
    params
  });
};

/**
 * 修改电子界桩
 */
export const updateEbmApi = (data: EbmUpdateParams) => {
  return http.request<any>("put", "/forward", { data });
};
